/*
 * THIS IS A GENERATED FILE!  DO NOT CHANGE THIS FILE!  CHANGE THE
 * CORRESPONDING TEMPLATE FILE, PLEASE!
 */

#include <shogun/base/SGObject.h>
#include <shogun/base/class_list.h>
#include <shogun/io/SerializableHdf5File.h>
#include <unistd.h>
#include <gtest/gtest.h>

using namespace shogun;

#ifdef HAVE_HDF5
{% set ignores = ['IndividualJobResultAggregator',
	'RationalApproximationCGMJob',
	'RationalApproximationIndividualJob',
	'LogRationalApproximationCGM',
	'LogRationalApproximationIndividual',
	'FactorDataSource',
	'Factor'] %}

{% for class in classes %}
{% if class in ignores or class.startswith('GUI') %}
TEST(SerializationHDF5, DISABLED_{{class}})
{% else %}
TEST(SerializationHDF5, {{class}})
{% endif %}
{
	std::string class_name("{{class}}");
	std::string file_template = "/tmp/shogun-unittest-serialization-hdfs-" + class_name + ".XXXXXX";
	char* filename = mktemp(const_cast<char*>(file_template.c_str()));
	CSGObject* object = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
	ASSERT_TRUE(object != NULL);

	// save object to an ascii file
	CSerializableHdf5File *file=new CSerializableHdf5File(filename, 'w');
	bool save_success = object->save_serializable(file);
	file->close();
	SG_UNREF(file);
	ASSERT_TRUE(save_success);

	// load parameter from an ascii file
	file=new CSerializableHdf5File(filename, 'r');
	CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
	ASSERT_TRUE(deserializedObject != NULL);
	bool load_success = deserializedObject->load_serializable(file);
	file->close();
	SG_UNREF(file);
	ASSERT_TRUE(load_success);

	// check whether they are equal
	ASSERT_TRUE(object->equals(deserializedObject));

	SG_UNREF(object)
	SG_UNREF(deserializedObject);

	int delete_success = unlink(filename);
	ASSERT_EQ(0, delete_success);
}
{% endfor %}

{% for class in template_classes %}
{% for type in types %}
{% if class in ignores %}
TEST(SerializationHDF5,DISABLED_{{class}}_{{type}})
{% else %}
TEST(SerializationHDF5,{{class}}_{{type}})
{% endif %}
{
	std::string class_name("{{class}}");
	std::string file_template = "/tmp/shogun-unittest-serialization-hdfs-" + class_name + "_{{type}}" + ".XXXXXX";
	char* filename = mktemp(const_cast<char*>(file_template.c_str()));
	CSGObject* object = new_sgserializable(class_name.c_str(), {{type}});
	ASSERT_TRUE(object != NULL);

	// save object to an ascii file
	CSerializableHdf5File *file=new CSerializableHdf5File(filename, 'w');
	bool save_success = object->save_serializable(file);
	file->close();
	SG_UNREF(file);
	ASSERT_TRUE(save_success);

	// load parameter from an ascii file
	file=new CSerializableHdf5File(filename, 'r');
	CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), {{type}});
	ASSERT_TRUE(deserializedObject != NULL);
	bool load_success = deserializedObject->load_serializable(file);
	file->close();
	SG_UNREF(file);
	ASSERT_TRUE(load_success);

	// check whether they are equal
	ASSERT_TRUE(object->equals(deserializedObject));

	SG_UNREF(object)
	SG_UNREF(deserializedObject);

	int delete_success = unlink(filename);
	ASSERT_EQ(0, delete_success);
}
{% endfor %}
{% endfor %}

#endif /* HAVE_HDF5 */
